package com.yyqx.web_maven.controller;

import com.google.gson.Gson;
import com.yyqx.web_maven.dao.AdimgsDao;
import com.yyqx.web_maven.entity.Adimgs;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "AdimgsServlet",urlPatterns = "/AdimgsServlet")
public class AdimgsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setHeader("Access-Control-Allow-Origin","*");
        response.setContentType("application/json;charset=UTF-8");
        AdimgsDao dao = new AdimgsDao();
        List<Adimgs> list = dao.getList();
        PrintWriter writer = response.getWriter();
        writer.write(new Gson().toJson(list));
        writer.flush();
        writer.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);

    }
}
